home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kcharselect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  8.1 KB  |  267 lines

  1. /* This file is part of the KDE libraries
  2.  
  3.    Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.    Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef kcharselect_h
  22. #define kcharselect_h
  23.  
  24. #include <qgridview.h>
  25. #include <qvbox.h>
  26. #include <qcombobox.h>
  27. #include <qspinbox.h>
  28. #include <qstring.h>
  29. #include <qpoint.h>
  30. #include <qstringlist.h>
  31.  
  32. #include <kdelibs_export.h>
  33.  
  34. class QFont;
  35. class QFontDatabase;
  36. class QMouseEvent;
  37. class QSpinBox;
  38. class KCharSelectTablePrivate;
  39. class KCharSelectPrivate;
  40.  
  41. /**
  42.  * @short Character selection table
  43.  *
  44.  * A table widget which displays the characters of a font. Internally
  45.  * used by KCharSelect. See the KCharSelect documentation for further
  46.  * details.
  47.  *
  48.  * @author Reginald Stadlbauer <reggie@kde.org>
  49.  */
  50.  
  51. class KDEUI_EXPORT KCharSelectTable : public QGridView
  52. {
  53.     Q_OBJECT
  54.  
  55. public:
  56.     KCharSelectTable( QWidget *parent, const char *name, const QString &_font,
  57.               const QChar &_chr, int _tableNum );
  58.  
  59.     virtual QSize sizeHint() const;
  60.     virtual void resizeEvent( QResizeEvent * );
  61.  
  62.     virtual void setFont( const QString &_font );
  63.     virtual void setChar( const QChar &_chr );
  64.     virtual void setTableNum( int _tableNum );
  65.  
  66.     virtual QChar chr() { return vChr; }
  67.  
  68. protected:
  69.     virtual void paintCell( class QPainter *p, int row, int col );
  70.  
  71.     virtual void mousePressEvent( QMouseEvent *e ) {  mouseMoveEvent( e ); }
  72.     virtual void mouseDoubleClickEvent ( QMouseEvent *e ){  mouseMoveEvent( e ); emit doubleClicked();}
  73.     virtual void mouseReleaseEvent( QMouseEvent *e ) { mouseMoveEvent( e ); emit activated( chr() ); emit activated(); }
  74.     virtual void mouseMoveEvent( QMouseEvent *e );
  75.  
  76.     virtual void keyPressEvent( QKeyEvent *e );
  77.  
  78.     void gotoLeft();
  79.     void gotoRight();
  80.     void gotoUp();
  81.     void gotoDown();
  82.  
  83.     QString vFont;
  84.     QChar vChr;
  85.     int vTableNum;
  86.     QPoint vPos;
  87.     QChar focusItem;
  88.     QPoint focusPos;
  89.     int temp;
  90.  
  91. signals:
  92.     void highlighted( const QChar &c );
  93.     void highlighted();
  94.     void activated( const QChar &c );
  95.     void activated();
  96.     void focusItemChanged();
  97.     void focusItemChanged( const QChar &c );
  98.     void tableUp();
  99.     void tableDown();
  100.     void doubleClicked();
  101.  
  102. private:
  103.     virtual void setFont(const QFont &f) { QGridView::setFont(f); }
  104.     void setToolTips();
  105. protected:
  106.     virtual void virtual_hook( int id, void* data );
  107. private:
  108.     KCharSelectTablePrivate* const d;
  109. };
  110.  
  111. /**
  112.  * @short Character selection widget
  113.  *
  114.  * This widget allows the user to select a character of a
  115.  * specified font in a table
  116.  *
  117.  * \image html kcharselect.png "Character Selection Widget"
  118.  *
  119.  * You can specify the font whose characters should be displayed via
  120.  * setFont() or in the constructor. Using enableFontCombo() you can allow the
  121.  * user to choose the font from a combob-box. As only 256 characters
  122.  * are displayed at once in the table, using the spinbox on the top
  123.  * the user can choose starting from which character the table
  124.  * displays them. This spinbox also can be enabled or disabled using
  125.  * enableTableSpinBox().
  126.  *
  127.  * KCharSelect supports keyboard and mouse navigation. Click+Move
  128.  * always selects the character below the mouse cursor. Using the
  129.  * arrow keys moves the focus mark around and pressing RETURN
  130.  * or SPACE selects the cell which contains the focus mark.
  131.  *
  132.  * To get the current selected character, use the chr()
  133.  * method. You can set the character which should be displayed with
  134.  * setChar() and the table number which should be displayed with
  135.  * setTableNum().
  136.  *
  137.  * @author Reginald Stadlbauer <reggie@kde.org>
  138.  */
  139.  
  140. class KDEUI_EXPORT KCharSelect : public QVBox
  141. {
  142.     Q_OBJECT
  143.     Q_PROPERTY( QString fontFamily READ font WRITE setFont )
  144.     Q_PROPERTY( int tableNum READ tableNum WRITE setTableNum )
  145.     Q_PROPERTY( bool fontComboEnabled READ isFontComboEnabled WRITE enableFontCombo )
  146.     Q_PROPERTY( bool tableSpinBoxEnabled READ isTableSpinBoxEnabled WRITE enableTableSpinBox )
  147.  
  148. public:
  149.     /**
  150.      * Constructor. @p font specifies which font should be displayed, @p
  151.      * chr which character should be selected and @p tableNum specifies
  152.      * the number of the table which should be displayed.
  153.      */
  154.     KCharSelect( QWidget *parent, const char *name,
  155.          const QString &font = QString::null, const QChar &chr = ' ', int tableNum = 0 );
  156.     ~KCharSelect();
  157.     /**
  158.      * Reimplemented.
  159.      */
  160.     virtual QSize sizeHint() const;
  161.  
  162.     /**
  163.      * Sets the font which is displayed to @p font
  164.      */
  165.     virtual void setFont( const QString &font );
  166.  
  167.     /**
  168.      * Sets the currently selected character to @p chr.
  169.      */
  170.     virtual void setChar( const QChar &chr );
  171.  
  172.     /**
  173.      * Sets the currently displayed table to @p tableNum.
  174.      */
  175.     virtual void setTableNum( int tableNum );
  176.  
  177.     /**
  178.      * Returns the currently selected character.
  179.      */
  180.     virtual QChar chr() const { return charTable->chr(); }
  181.  
  182.     /**
  183.      * Returns the currently displayed font.
  184.      */
  185.     virtual QString font() const { return fontCombo->currentText(); }
  186.  
  187.     /**
  188.      * Returns the currently displayed table
  189.      */
  190.     virtual int tableNum() const { return tableSpinBox->value(); }
  191.  
  192.     /**
  193.      * If @p e is set to true, the combobox which allows the user to
  194.      * select the font which should be displayed is enabled, else
  195.      * disabled.
  196.      */
  197.     virtual void enableFontCombo( bool e ) { fontCombo->setEnabled( e ); }
  198.  
  199.     /**
  200.  
  201.      * If @p e is set to true, the spinbox which allows the user to
  202.      * specify which characters of the font should be displayed, is
  203.      * enabled, else disabled.
  204.      */
  205.     virtual void enableTableSpinBox( bool e ) { tableSpinBox->setEnabled( e ); }
  206.  
  207.     /**
  208.      * Returns wether the font combobox on the top is enabled or
  209.      * disabled.
  210.      *
  211.      * @see enableFontCombo()
  212.      */
  213.     virtual bool isFontComboEnabled() const { return fontCombo->isEnabled(); }
  214.  
  215.     /**
  216.      * Returns wether the table spinbox on the top is enabled or
  217.      * disabled.
  218.      *
  219.      * @see enableTableSpinBox()
  220.      */
  221.     virtual bool isTableSpinBoxEnabled() const { return tableSpinBox->isEnabled(); }
  222.  
  223. protected:
  224.     virtual void fillFontCombo();
  225.     static void cleanupFontDatabase();
  226.  
  227.     QComboBox *fontCombo;
  228.     QSpinBox *tableSpinBox;
  229.     KCharSelectTable *charTable;
  230.     QStringList fontList;
  231.     static QFontDatabase * fontDataBase;
  232.  
  233. protected slots:
  234.     void fontSelected( const QString &_font );
  235.     void tableChanged( int _value );
  236.     void charHighlighted( const QChar &c ) { emit highlighted( c ); }
  237.     void charHighlighted() { emit highlighted(); }
  238.     void charActivated( const QChar &c ) { emit activated( c ); }
  239.     void charActivated() { emit activated(); }
  240.     void charFocusItemChanged() { emit focusItemChanged(); }
  241.     void charFocusItemChanged( const QChar &c ) { emit focusItemChanged( c ); }
  242.     void charTableUp() { if ( tableNum() < 255 ) setTableNum( tableNum() + 1 ); }
  243.     void charTableDown() { if ( tableNum() > 0 ) setTableNum( tableNum() - 1 ); }
  244.     void slotDoubleClicked() { emit doubleClicked(); }
  245.     void slotUnicodeEntered();
  246.     void slotUpdateUnicode( const QChar &c );
  247. signals:
  248.     void highlighted( const QChar &c );
  249.     void highlighted();
  250.     void activated( const QChar &c );
  251.     void activated();
  252.     void fontChanged( const QString &_font );
  253.     void focusItemChanged();
  254.     void focusItemChanged( const QChar &c );
  255.     void doubleClicked();
  256.  
  257. private:
  258.     virtual void setFont(const QFont &f) { QVBox::setFont(f); }
  259. protected:
  260.     virtual void virtual_hook( int id, void* data );
  261. private:
  262.     class KCharSelectPrivate;
  263.     KCharSelectPrivate* const d;
  264. };
  265.  
  266. #endif
  267.